<template>
  <!-- <a-tooltip>
    <template #title>prompt text</template>
    Tooltip will show when mouse enter. -->
  <div style="position: relative; top: 50px">
    <bm-overlay ref="customOverlay" :class="{sample: true, active}" pane="labelPane" @draw="draw">
      <div v-text="text" @click="handleClick"></div>
    </bm-overlay>
  </div>
  <!-- </a-tooltip> -->
</template>

<script>
  export default {
    props: ['text', 'position', 'active'],
    watch: {
      position: {
        handler() {
          this.$refs.customOverlay.reload()
        },
        deep: true
      }
    },
    methods: {
      handleClick() {
        global.alert('Well done.')
      },
      draw({el, BMap, map}) {
        const {lng, lat} = this.position
        const pixel = map.pointToOverlayPixel(new BMap.Point(lng, lat))
        el.style.left = pixel.x - 60 + 'px'
        el.style.top = pixel.y - 20 + 'px'
      }
    }
  }
</script>

<style>
  .sample {
    width: 120px;
    height: 20px;
    line-height: 20px;
    background: rgba(29, 90, 236, 0.6);
    overflow: hidden;
    box-shadow: 0 0 5px rgb(29, 90, 236);
    color: #fff;
    text-align: center;
    /* padding: 10px; */
    position: absolute;
    margin-top: 42px;
  }
  .sample.active {
    background: rgba(29, 90, 236, 0.85);
    color: #fff;
  }
</style>
